<template>
  <div>
    <span class="icon1"
      ><img src="../assets/images/导航栏首页.png" width="20px"
    /></span>
    <span class="icon4"> 平台首页</span>
    <span class="icon2"
      ><img src="../assets/images/导航栏坐标.png" width="20px"
    /></span>
    <span class="icon3">辽宁</span>

    <div class="header_box">
      <div class="bread">
        <el-breadcrumb separator="|">
          <el-breadcrumb-item :to="{ path: '/' }">我的订单</el-breadcrumb-item>
          <el-breadcrumb-item><a href="/">我的消息</a></el-breadcrumb-item>
          <el-breadcrumb-item><a href="/">活动列表</a></el-breadcrumb-item>
          <el-breadcrumb-item><a href="/">网站无障碍</a></el-breadcrumb-item>
          <el-dropdown trigger="click" @command="handleCommand">
            <span class="el-dropdown-link" v-if="isUserLook">
              用户 {{ username }} 您好<i
                class="el-icon-arrow-down el-icon--right"
              ></i>
            </span>
            <a @click="goLogin" v-else>登录</a>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="person">个人主页</el-dropdown-item>
              <el-dropdown-item command="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-breadcrumb>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Header",

  data() {
    return {
      username: sessionStorage.getItem("username") || "",
      // isLook: true,
      isUserLook: false,
    };
  },

  created() {
    this.isUserLook = this.username.length > 0;
  },

  methods: {
    goLogin() {
      this.$router.push("/login");
    },
    handleCommand(command) {
      if (command == "logout") {
        sessionStorage.removeItem("username");
        sessionStorage.removeItem("token");
        window.location.reload();
      }
      if (command == "person") {
        this.$router.push("/personal");
      }
    },
  },
};
</script>

<style scoped>
.el-header,
.el-footer{
  background-color: rgb(235, 218, 218);
  color: #333;
  text-align: center;
  line-height: 40px;
}
.el-breadcrumb{
  margin-top: 15px;
}
.el-dropdown-link {
  cursor: pointer;
  color: black;
}
.el-dropdown{
  bottom: 6px;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.header_box {
  float: right;
  margin-right: 300px;
}
.bread {
  float: right;
  margin-top: 10px;
  margin-left: 30px;
}
.icon1 {
  margin-left: 340px;
  margin-top: 3px;
  float: left;
}
.icon2 {
  margin-left: 30px;
  margin-top: 3px;
  float: left;
}
.el-dropdown-link {
  font-size: 14px;
}
.icon3 {
  float: left;
}
.icon4 {
  float: left;
  margin-left: 5px;
}
</style>
